<?php
/*------------------------------------------------------------------------
 * BannerModel.class.php 
 *
 * Banner模型
 * 	
 * Created on 2015-01-21
 *
 * Author: hwc123 <hwc123@139.com>
 * 
 * Copyright (c) 2015 http://www.qingtajiao.com All rights reserved.
 * ------------------------------------------------------------------------
 */

namespace Common\Model;
use Think\Model;

class BannerModel extends Model{

	/**
	 * 获取BANNER
	 * @param  string $type
	 */
	public function get_list($type = 'index', $city_id = 0, $category_id = 0){
		$where['is_delete'] = 0;
		$where['status']    = 1;
		$where['type']      = $type;
		$where['city_id']   = array(
			array('eq', 0), 
			array('eq', $city_id), 
			'or'
		);
		if($category_id){
			$where['category_id'] = $category_id;
		}
		$list = D('Banner')->field('title,images_id,category_id,open_type,open_content,description')->where($where)->order('order_id,id desc')->select();
		$data = array();
		if($list){
			foreach ($list as $rs) {
				$rs['images_url'] = D('File')->get_path($rs['images_id']);
				switch ($rs['open_type']) {
					// 免费合同详情
					case 'free_agreement_detail':
						$open_url    = U('FreeAgreement/detail', array('agreement_id' => $rs['open_content']));
						break;

					// 定制合同详情
					case 'custom_agreement_detail':
						$open_url    = U('CustomAgreement/detail', array('agreement_id' => $rs['open_content']));
						break;
					
					// 创业学院详情
					case 'schools_detail':
						$open_url    = URL('Schools/detail', array('article_id' => $rs['open_content']), 'schools/detail_' . $rs['open_content']);
						break;

					// 知识库详情
					case 'knowledge_detail':
						$open_url    = URL('Knowledge/detail', array('article_id' => $rs['open_content']), 'knowledge/detail_' . $rs['open_content']);
						break;

					// 内置浏览器
					case 'browser':
						$open_url    = $rs['open_content'];
						break;

					default:
						$open_url    = '';
						break;
				}
				$rs['category_name'] = $rs['category_id'] ? D('Category')->get_name($rs['category_id']) : '';

				$rs['open_url']   = $open_url;
				$rs['api_params'] = $api_params;
				unset($rs['images_id']);
				$data[] = $rs;
			}
		}
		return $data;
	}
}
